

package util.lang.sql;

import java.util.LinkedList;

public class SqlSingleFilterStatement extends SqlFilterStatement {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String tableName;
	private String columeName;
	private String filterOperator;
	private Object filterValue;

	public String getTableName() {
		return this.tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getColumeName() {
		return this.columeName;
	}
	public void setColumeName(String columeName) {
		this.columeName = columeName;
	}

	public String getFilterOperator() {
		return this.filterOperator;
	}
	public void setFilterOperator(String filterOperator) {
		this.filterOperator = filterOperator;
	}

	public Object getFilterValue() {
		return this.filterValue;
	}
	public void setFilterValue(Object filterValue) {
		this.filterValue = filterValue;
	}
	
	public SqlSingleFilterStatement() {
		this.tableName = "";
		this.columeName = "";
		this.filterOperator = "=";
		this.filterValue = null;
	}
	public SqlSingleFilterStatement(String columnName, Object filterValue) {
		this.tableName = "";
		this.columeName = columnName;
		this.filterOperator = "=";
		this.filterValue = filterValue;
	}
	public SqlSingleFilterStatement(String columnName, String filterOperator, Object filterValue) {
		this.tableName = "";
		this.columeName = columnName;
		this.filterOperator = filterOperator;
		this.filterValue = filterValue;
	}
	public SqlSingleFilterStatement(String tableName ,String columnName, String filterOperator, Object filterValue) {
		this.tableName = tableName;
		this.columeName = columnName;
		this.filterOperator = filterOperator;
		this.filterValue = filterValue;
	}
	
	@Override
	public String getSql() {
		StringBuffer sb = new StringBuffer();
		if (tableName != null && !"".equals(tableName)) {
			sb.append(tableName);
			sb.append('.');
		}
		sb.append(columeName);
		sb.append(' ');
		sb.append(filterOperator);
		sb.append(' ');
		sb.append('?');
		return sb.toString();
	}
	
	@Override
	public LinkedList<Object> getValues() {
		LinkedList<Object> list = new LinkedList<Object>();
		list.add(filterValue);
		return list;
	}
	
	@Override
	public String toString() {
		return this.getSql();
	}
}
